<?php

/**
 * 前台 首页 模块 Model
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: ajkeyworld.class.php 1402 2011-03-03 10:15:34Z zhangwentao $
 * http://www.t-mac.org；
 */
class ajkeyword extends Model
{

    private $hotel_table;
    private $hotel_left_model;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->connect();
        $this->hotel_table = '#@__hotel';
        $this->hotel_left_model = Tmac::model('hotelLeft');
    }

    /**
     * 取酒店总数/评价总数
     * @return<String>
     */
    public function getHotelCount()
    {
        $sql = "SELECT COUNT(*) AS count FROM $this->hotel_table";
        $hotelcount = $this->db->cacheGetOne($sql, 604800);
        //评价数
        $comment_count = $hotelcount * 5 + 553;
        $this->assign('hotelcount', $hotelcount);
        $this->assign('comment_count', $comment_count);
        return $hotelcount;
    }

    /**
     * 设置首页默认第一的搜索城市
     * @global <type> $cfg_indexCitylist
     * @return <type>
     */
    public function setDefaultCity()
    {
        global $cfg_indexCitylist;
        $uncityinfo_ary = explode(',', $cfg_indexCitylist);
        $uncityinfo = explode('|', $uncityinfo_ary[0]);
        foreach ($uncityinfo_ary AS $k => $v) {
            if ($k > 8)
                break;
            $unarray = explode('|', $v);
            $uncityinfo_array[$k]['cityname'] = $unarray[1];
            $uncityinfo_array[$k]['cityid'] = $unarray[0];
        }
        $this->assign('uncityinfo_array', $uncityinfo_array);
        $this->assign('uncityinfo', $uncityinfo);
        return $uncityinfo;
    }

    /**
     * 取城市地标
     * @param <type> $cityid
     * @param <type> $limit
     * @param <type> $page
     * @return <type>
     */
    public function citylable($cityid, $limit, $page = 1)
    {
        global $cfg_uid, $cfg_mid;
        $nofind_lable = '';
        $cfg_apiurl = $GLOBALS['cfg_apiurl'];
        $xml_url = $cfg_apiurl . "lable.asp?u=$cfg_uid&m=$cfg_mid&cityid=$cityid&pg={$page}";
        $xml_root = VAR_ROOT . "xml/citylable/";
        $xml_name = "citylable_{$cityid}_{$page}.xml";
        $this->hotel_left_model->createXML($xml_url, $xml_root, $xml_name);
        $xmlstring = $xml_root . $xml_name;

        $dom = new DomDocument;
        $dom_load = $dom->load($xmlstring);
        if ($dom_load) {
//            $maplables = $dom->getElementsByTagName('maplable');
//            $totalput = $maplables->item(0)->getAttribute("totalput");
            $lable = $dom->getElementsByTagName("lable");
            $lable_ary = array();
            if ($lable->length > 0) {
                foreach ($lable as $k => $basexml) {
                    if ($k == $limit)
                        break;
                    $lable_ary[$k]['key'] = $basexml->getAttribute('key');
                    $lable_ary[$k]['cityid'] = $basexml->getAttribute('cityid');
                    $lable_ary[$k]['cityname'] = $basexml->getAttribute('cityname');
                    $lable_ary[$k]['classid'] = $basexml->getAttribute('classid');
                    $lable_ary[$k]['classname'] = $basexml->getAttribute('classname');
                }
            } else {
                $nofind_lable = "暂无此城市地标列表!";
            }
        } else {
            $nofind_lable = "暂无此城市地标列表!";
        }

        $this->assign('city_lable_array', $lable_ary);
        $this->assign('nofind_city_lable', $nofind_lable);
        return $lable_ary;
    }

}